home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / filters.zip / UNIQUE.ASM < prev    next >
Assembly Source File  |  1986-11-27  |  3KB  |  114 lines

  1.     Name unique
  2.     Title
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that reads a sorted file and removes
  7.     all duplicated lines.  Sending a sorted list of words will
  8.     result in a list of all words, once each.
  9.  
  10.     Examples:
  11.  
  12. /
  13. ;===================================================================
  14. code    segment    public
  15. ;===================================================================
  16. ;
  17. ;    command line is at 80h of psp - first byte is length
  18. ;
  19.     org    80h
  20. parmsize    db    ?
  21. parm        db    7fh dup (?)
  22. ;
  23. ; .com starts at 100h - but must jump around any data area
  24. ;
  25.     org    100h            ; com file starts here
  26.     assume    cs:code,ds:code,es:code
  27. unique:
  28.     jmp    clear
  29. ;===================================================================
  30. ;
  31. ; data area for .com programs
  32. ; Uncomment (**) statements and comment (&&) statements
  33. ; if you need two different buffers.
  34. ;
  35. buffersize    equ    255
  36. bufsiz    db     buffersize
  37. bufcnt    db    ?
  38. buffer    db    buffersize dup (?)        ; (&&)
  39. ;
  40. savcnt    db    ?
  41. savbuf    db    buffersize dup (0h)        ; init to nulls
  42. ;
  43. ;===================================================================
  44. clear:
  45. ;
  46. ; start of actual code is here (clear)
  47. ;
  48. ;
  49. ; Read a line from standard input.  Char count is in bufcnt. Does not
  50. ; include the <cr>.
  51. ;
  52. again:
  53.     lea    dx,buffer    ; point at input area
  54.     mov    bufcnt,0h    ; init size to zero
  55. ioloop:
  56.     mov    bx,0h        ; input handle
  57.     mov    cx,1h        ; # of char to read
  58.     mov    ah,3fh        ; dos read function
  59.     int    21h        ; dos function call
  60. ;
  61.     jc    oops        ; io error!
  62.     cmp    ax,0h        ; if zero, eof!
  63.     jz    linedone
  64. ;
  65.     inc    bufcnt        ; adjust buffer size for new character
  66.     mov    si,dx
  67.     cmp    byte ptr [si],0Ah    ; if linefeed, line is done.
  68.     je    linedone
  69.     inc    dx        ; point to next character spot
  70.     jmp    ioloop        ; go get another character
  71. linedone:
  72.     cmp    bufcnt,0h    ; if zero, really eof!
  73.     jz    oops
  74. ;
  75. ; Now compare the line just input to the previous line in savbuf.
  76. ; If they are different, print the new line and store in in savbuf.
  77. ; If they match, jump to again and read another line.
  78. ; (The first line input will never match savbuf - savbug contains
  79. ; nulls.)
  80. ;
  81.     xor    cx,cx        ; zero cx first
  82.     mov    cl,bufcnt    ; # of chars in line
  83.     cmp    cl,savcnt    ; to save line - if not equal, skip
  84.     jne    printit
  85.     lea    si,buffer    ; input line
  86.     lea    di,savbuf    ; previous line
  87.     repe    cmpsb        ; compare each byte.
  88.     je    again        ; they matched - go get another line.
  89. ;
  90. ; Now print the line and save it in a compare buffer.
  91. ;
  92. printit:
  93.     xor    cx,cx        ; zero out cx
  94.     mov    cl,bufcnt    ; # of characters to output
  95.     lea    dx,buffer    ; input line buffer
  96.     mov    bx,1h        ; standard output device
  97.     mov    ah,40h        ; dos write function
  98.     int    21h        ; invoke dos function
  99. ;
  100. ; copy buffer to savbuf.
  101. ;
  102.     lea    si,bufcnt    ; source buffer pointer
  103.     lea    di,savcnt    ; destination buffer pointer
  104.     xor    cx,cx
  105.     mov    cl,bufcnt    ; size of source buffer
  106.     inc    cx        ; include size counter, too.
  107.     rep    movsb        ; character move
  108.  
  109.     jmp    again        ; repeat until end of file or error
  110. oops:
  111.     int    20h        ; return to dos
  112. code    ends
  113.     end    unique
  114.